package com.globallogic.university;

import org.testng.Assert;
import org.testng.annotations.Test;

import com.globallogic.university.documents.Curriculum;
import com.globallogic.university.events.Lecture;
import com.globallogic.university.people.Student;
import com.globallogic.university.people.StudentGroup;
import com.globallogic.university.people.Teacher;

public class UniversityTest extends TestHelper {
	
	@Test
	public void shouldAddStudent() {
		// given
		University uni = new University();
		
		// when
		Student student = new Student("John", "Doe");
		uni.addStudent(student);

		// then
		Assert.assertTrue(uni.getAllStudents().contains(student));
	}
	
	@Test
	public void shouldAddTeacher() {
		// given
		University uni = new University();
		
		// when
		Teacher teacher = new Teacher("John", "Doe");
		uni.addTeacher(teacher);

		// then
		Assert.assertTrue(uni.getAllTeachers().contains(teacher));
	}
	
	@Test
	public void shouldAddLecture() {
		// given
		University uni = new University();
		
		// when
		Lecture lecture = new Lecture();
		uni.addLecture(lecture);

		// then
		Assert.assertTrue(uni.getAllLectures().contains(lecture));
	}
	
	@Test
	public void shouldAddCurriculum() {
		// given
		University uni = new University();
		
		// when
		Curriculum curriculum = new Curriculum();
		uni.addCurriculum(curriculum);

		// then
		Assert.assertTrue(uni.getAllCurriculums().contains(curriculum));
	}
	
	@Test
	public void shouldDeleteStudent() {
		// given
		University uni = new University();
		
		Student student = new Student("John", "Doe");
		uni.addStudent(student);

		// when
		uni.deleteStudent(student);
		
		// then
		Assert.assertFalse(uni.getAllStudents().contains(student));
	}
	
	@Test
	public void shouldDeleteTeacher() {
		// given
		University uni = new University();
		
		Teacher teacher = new Teacher("John", "Doe");
		uni.addTeacher(teacher);

		// when
		uni.deleteTeacher(teacher);
		
		// then
		Assert.assertFalse(uni.getAllTeachers().contains(teacher));
	}
	
	@Test
	public void shouldDeleteLecture() {
		// given
		University uni = new University();
		
		Lecture lecture = new Lecture();
		uni.addLecture(lecture);

		// when
		uni.deleteLecture(lecture);
		
		// then
		Assert.assertFalse(uni.getAllLectures().contains(lecture));
	}
	
	@Test
	public void shouldDeleteCurriculum() {
		// given
		University uni = new University();
		
		Curriculum curriculum = new Curriculum();
		uni.addCurriculum(curriculum);

		// when
		uni.deleteCurriculum(curriculum);
		
		// then
		Assert.assertFalse(uni.getAllCurriculums().contains(curriculum));
	}
	
	@Test
	public void shouldShowStudentsInGroup() {
		// given
		University uni = new University();
		
		String groupId = "Group1";
		StudentGroup group = new StudentGroup(groupId);
		uni.addGroup(group);
		
		String firstName1 = "John";
		String lastName1 = "Doe";
		Student student1 = createStudent(firstName1, lastName1);
		uni.addStudent(student1);
		group.enrollStudent(student1);
		
		String firstName2 = "Jane";
		String lastName2 = "Doe";
		Student student2 = createStudent(firstName2, lastName2);
		uni.addStudent(student2);
		group.enrollStudent(student2);
		
		// when
		String actual = uni.showEnrolledStudents(group);
		
		// then
		String expected = String.format("%s:\n" +
										"%s %s\n" +
										"%s %s\n", 
										groupId, 
										lastName1, firstName1, 
										lastName2, firstName2);
		Assert.assertEquals(actual, expected);
	}


}
